package es.uma.scgt.dao;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class ManejadorSession {
	
	public static UserDetails actualDetaillesDeUsuario(){
	    SecurityContext securityContext = SecurityContextHolder.getContext();
	    Authentication authentication = securityContext.getAuthentication();
	    if (authentication != null) {
	        Object principal = authentication.getPrincipal();
	        return (UserDetails) (principal instanceof UserDetails ? principal : null);
	    }
	    return null;
	}
	
	public static String email(){
		return actualDetaillesDeUsuario().getUsername();
	}

} 
 